package com.project.mvprxsample.presenters;

import android.content.Context;

import com.project.mvprxsample.bean.BaseResult;
import com.project.mvprxsample.bean.TestDB;
import com.project.mvprxsample.bean.UserInfo;
import com.project.mvprxsample.model.UserMode;
import com.project.mvprxsample.net.MyObserver;
import com.project.mvprxsample.view.BaseView;

import java.util.List;

/**
 * Created by lvyang on 2017/5/12.
 */

public class UserPresenter extends BasePresenter<BaseView<UserInfo>> {

    UserMode userMode;

    public UserPresenter(Context context, BaseView<UserInfo> view) {
        super(context, view);
    }

    @Override
    public void initModel() {
        userMode = new UserMode(mContext);
    }

    /**
     * 保存用户信息
     *
     * @param userName userName
     * @param phone    phone
     */
    public void saveUserInfo(String userName, String phone) {
        userMode.save(new TestDB(userName, phone));
    }

    /**
     * 测试查询
     *
     * @param userName
     * @return
     */
    public List<TestDB> getUserInfoByUserName(String userName) {
        return userMode.getQueryByColumn("USER_NAME", userName);
    }

    /**
     * 测试删除
     *
     * @param userName
     * @return
     */
    public boolean deleteByUserName(String userName) {
        return userMode.deleteByColumn("USER_NAME", userName);
    }

    /**
     * 测试接口
     *
     * @param userName
     * @param passWord
     */
    public void userLogin(String userName, String passWord) {
        resultJSON(mBaseApi.login(userName, passWord), new MyObserver(mContext) {

            @Override
            public void onCompleted() {
                super.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
            }

            @Override
            public void onNext(BaseResult baseResult) {
                super.onNext(baseResult);


            }
        });
    }

}
